package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.CategoryAllBeen;
import cn.xfdzx.android.apps.shop.bean.OneCategoryBeen;

/**
 * Created by Administrator on 2017/12/29.
 */

public class SellingGoodsLeftLVAdapter extends BaseAdapter {
    private List<CategoryAllBeen.DataBean> data;
    private Context mContext;
    private int selectItem = 0;

    public SellingGoodsLeftLVAdapter(Context context) {

        this.mContext = context;
    }


    public int getSelectItem() {
        return selectItem;
    }

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    @Override
    public int getCount() {
        return null==data?0:data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        /**
         * 控件的复用机制
         */
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_selling_goods_left, viewGroup, false);
            viewHolder.tv_left_title = (TextView) convertView.findViewById(R.id.tv_left_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_left_title.setText(data.get(i).getName());
        if (i == selectItem) {
            viewHolder.tv_left_title.setTextSize(14);
            viewHolder.tv_left_title.setBackgroundColor(Color.WHITE);
            viewHolder.tv_left_title.setTextColor(mContext.getResources().getColor(R.color.color_333333));
        } else {
            viewHolder.tv_left_title.setTextSize(13);
            viewHolder.tv_left_title.setBackgroundColor(mContext.getResources().getColor(R.color.color_F8F8F8));
            viewHolder.tv_left_title.setTextColor(mContext.getResources().getColor(R.color.color_595959));
        }
        return convertView;

    }

    public void setData(List<CategoryAllBeen.DataBean> data) {
       this.data=data;
       notifyDataSetChanged();
    }

    private class ViewHolder {
        TextView tv_left_title;
    }
}
